using UnityEngine;
using UnityEngine.UI;

public class DashSkillController : Skill
{
    [Header("Dash")] [SerializeField] private UiSkillTreeSlot dashUnlockButton;
    public bool DashUnlocked { get; private set; }

    [Header("Clone on dash")] [SerializeField]
    private UiSkillTreeSlot cloneOnDashUnlockButton;

    public bool CloneOnDashUnlocked { get; private set; }

    [Header("Clone on arrival")] [SerializeField]
    private UiSkillTreeSlot cloneOnArrivalDashUnlockButton;

    public bool CloneOnArrivalUnlocked { get; private set; }

    protected override void Start()
    {
        base.Start();
        dashUnlockButton.GetComponent<Button>().onClick.AddListener(UnlockDash);
        cloneOnDashUnlockButton.GetComponent<Button>().onClick.AddListener(UnlockCloneOnDash);
        cloneOnArrivalDashUnlockButton.GetComponent<Button>().onClick.AddListener(UnlockCloneOnArrival);
    }

    protected override void CheckUnlock()
    {
        UnlockDash();
        UnlockCloneOnDash();
        UnlockCloneOnArrival();
    }

    private void UnlockDash()
    {
        if (dashUnlockButton.unlocked == false || DashUnlocked) return;
        DashUnlocked = true;
    }

    private void UnlockCloneOnDash()
    {
        if (cloneOnDashUnlockButton.unlocked == false || CloneOnDashUnlocked) return;
        CloneOnDashUnlocked = true;
    }

    private void UnlockCloneOnArrival()
    {
        if (cloneOnArrivalDashUnlockButton.unlocked == false || CloneOnArrivalUnlocked) return;
        CloneOnArrivalUnlocked = true;
    }

    public void CloneOnDash()
    {
        if (CloneOnDashUnlocked)
            SkillManager.Clone.Create(Player.transform);
    }

    public void CloneOnArrival()
    {
        if (CloneOnArrivalUnlocked)
            SkillManager.Clone.Create(Player.transform);
    }
}